package com.maxd.adapter;

import com.maxd.component.sequence.SeqScene;
import com.maxd.component.sequence.SeqTools;
import com.maxd.service.common.ICommonService;
import com.maxd.service.selfWXPay.WxPayV3Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ApplicationStartedHandler implements ApplicationListener<ApplicationReadyEvent> {

    @Autowired
    private ICommonService commonService;

    @Autowired
    private WxPayV3Service wxPayV3Service;

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        log.info("开始系统预热处理...");
        try {
            initSeq();
            commonService.loadConfigs(false);
            wxPayV3Service.initJsapiService(false);
        } catch (Exception e) {
            log.error("系统预热处器失败", e);
        }
        log.info("系统预热处理完成...");
    }

    private void initSeq() {
        log.info("加载流水号...");
        SeqScene[] values = SeqScene.values();
        for (SeqScene value : values) {
            log.info("场景号:{}, 流水号:{}",value.getCode(), SeqTools.seq(value, 10));
        }
    }

}
